
local list = load_excel('物品数据.xlsx','黑市')
local golds = {10000,15000,20000}
ac.game:event '游戏-创建金猪'(function(_,player,point,level)
    local hero = player.hero
    if not hero then
        return
    end
    local time = 30
    local text = nil
    local unit = player:add_enemy('金猪',point)
    local gold_max = golds[math.ceil(level/4)]
    unit:set_enemy_level(level)
    unit:issue_order('attack',hero)
    unit:loop(10*1000,function()
        unit:issue_order('attack',hero)
    end)
    unit:set('移动速度',200)
    unit:set('基础攻击',10)
    unit:set('攻击范围',100)
    unit:loop(1000,function(t)
        unit.name = ('金猪(|cffffff00%s|r)'):format(time)
        if time==0 then
            unit:remove()
        end
        time = time - 1
    end):on_timer()
    unit:event '单位-拦截受到伤害'(function(_,data)
        local owner = data.source.owner
        return owner~=player
    end)
    unit:event '单位-受到伤害'(function(_,_,source,data)
        local owner = source.owner
        local gold = data.real_damage/unit:get('生命上限') * gold_max
        player:add('金币',gold)
        if gold>1 then
            ac.ui_tag {
                string = ('|cffffff00+%0.f'):format(gold),
                speed = 200,
                angle = math.random(45,135),
                life = 1,
                fade = 0.5,
                position = unit:get_point(),
                icon = [[图标\金币.blp]],
            }
        end
        
    end)
    unit:event '单位-死亡'(function()
        local hero = player.hero
        unit:remove()
        if hero then
            local items = table.random_table(list,3)
            for _,da in ipairs(items) do
                local item = hero:add_item(da.name)
                barrage(player,('|cffff9900%s|r'):format(item:get_title()))
            end
        end
    end)
end)

